package com.mornd.gulimall.member.controller;

import com.mornd.gulimall.common.core.result.AjaxResult;
import com.mornd.gulimall.common.core.validation.UpdateGroup;
import com.mornd.gulimall.member.entity.MemberLevel;
import com.mornd.gulimall.member.service.IMemberLevelService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

import static com.mornd.gulimall.common.core.result.AjaxResult.success;

/**
 * <p>
 * 会员等级 前端控制器
 * </p>
 *
 * @author mornd
 * @since 2023-07-31
 */
@RestController
@RequestMapping("/member/memberLevel")
public class MemberLevelController {
    @Resource(type = IMemberLevelService.class)
    private IMemberLevelService service;

    @GetMapping
    public AjaxResult list(MemberLevel query) {
        return success(service.list(query));
    }


    /**
     * 筛选所有的会员等级
     * @return
     */
    @GetMapping("/filter")
    public AjaxResult filter(MemberLevel query) {
        return success(service.filter(query));
    }

    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        return success(service.getById(id));
    }

    @PutMapping
    public AjaxResult save(@RequestBody @Validated MemberLevel entity) {
        service.save(entity);
        return success();
    }

    @PostMapping
    public AjaxResult update(@RequestBody @Validated(UpdateGroup.class) MemberLevel entity) {
        service.updateById(entity);
        return success();
    }

    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids) {
        service.removeByIds(Arrays.asList(ids));
        return success();
    }

}
